package org.python.util;

import java.io.*;
import java.net.*;

public abstract class AbstractLibLoader {
	public String retrieveLib(URL remoteLib) throws IOException {
		File tmpLib;
		InputStream fisLib;
		OutputStream fosLib;
		
		try {
			fisLib = remoteLib.openStream();
			tmpLib = File.createTempFile("lib_", ".jar");
			fosLib = new FileOutputStream(tmpLib);
			
			byte[] buffer = new byte[1024];
			while (true) {
				int bytesRead = fisLib.read(buffer);
				if (bytesRead < 0) break;
				fosLib.write(buffer, 0, bytesRead);
			}
			
			tmpLib.deleteOnExit();
		} catch (IOException e) {
			throw e;
		}
		
		return tmpLib.getAbsolutePath();
	}
	
	public abstract void load(URL remoteLib);
}
